package com.example.dao;

import com.example.entity.ClassInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author 涛某
 * @version 1.0
 * @date 2024/3/27 9:32
 */
@Repository
public interface ClassInfoDao  extends Mapper<ClassInfo> {
    @Select("select class.*,teacher.name as teachername,zhuanye.name as zhuanyename from class\n" +
            "LEFT JOIN teacher on class.teacherid = teacher.id\n" +
            "LEFT JOIN zhuanye on class.zhuanyeid = zhuanye.id")
    List<ClassInfo> findAll();
    @Insert("insert into class (name,description,zhuanyeid,score,teacherid,kaiban,time,location,yiyuan) " +
            "values(#{name},#{description},#{zhuanyeid},#{score},#{teacherid},#{kaiban},#{time},#{location},#{yiyuan})")
    void add(ClassInfo classInfo);
    @Update("update class  " +
            "set name = #{name},description = #{description},zhuanyeid = #{zhuanyeid},score = #{score},teacherid = #{teacherid},kaiban = #{kaiban}," +
            "time = #{time},location = #{location},yixuan = #{yixuan}")
    void update(ClassInfo classInfo);
    @Delete("delete * from class where id = #{id}")
    void del(Long id);
    @Select("SELECT\n" +
            "\ta.*,\n" +
            "\tb. NAME as teachername,\n" +
            "  c.name as zhuanyename\n" +
            "FROM\n" +
            "\tclass AS a\n" +
            "LEFT JOIN teacher AS b ON a.teacherid = b.id\n" +
            "LEFT JOIN zhuanye as c on b.zhuanyeid = c.id\n" +
            "WHERE b.name like CONCAT('%',#{search},'%')\n ")
    List<ClassInfo> findSearch(String search);
}
